﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using Bestlife.ERP.DataAccess;
using System.Data.SqlClient;

/// <summary>
/// Summary description for BonusByRicpt
/// </summary>
/// 

namespace Bestlife.ERP.DataAccess
{
    public class BonusByRicpt
    {
        SqlDataReader rdR_Status;
        List<Entities.E_Receipt> listrtn = new List<Entities.E_Receipt>();
        string Rids = "";

        public BonusByRicpt()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public List<Entities.E_Receipt> returnList(string Rtndate)
        {

            string Date_start = Rtndate + " " + "00:00:00.000";
            string Date_End = Rtndate + " " + "23:59:00.000";
            //format ==> '2012-09-05 00:00:00.000' AND '2012-09-05 18:00:00.000'";

            try
            { //try
                
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);

                String Ssql = "SELECT * from Tbl_Receipt  where Rcpt_Date BETWEEN '"+Date_start+"' AND '"+Date_End+"'";
                //SqlDataReader ldr = Bestlife.ERP.DataAccess.clsCon.ReadTable(Ssql);


                rdR_Status = clsCon.ReadTable(Ssql);


                while (rdR_Status.Read())
                {

                    Entities.E_Receipt rcpt = new Entities.E_Receipt();
                    rcpt.Rcpt_no =int.Parse(rdR_Status["R_ID"].ToString());
                    rcpt.D_id = rdR_Status["D_id"].ToString();
                    rcpt.D_name = rdR_Status["D_name"].ToString();
                    rcpt.Total_Price = rdR_Status["Total_Price"].ToString();
                    rcpt.Toatal_PV = rdR_Status["Toatal_PV"].ToString();
                    rcpt.Total_BV = rdR_Status["Total_BV"].ToString();
                    rcpt.Cashier_name = rdR_Status["cashier_Name"].ToString();
                    rcpt.R_date = (DateTime)rdR_Status["Rcpt_Date"];
                    listrtn.Add(rcpt);
                }

            } //try

            catch (Exception err)
            {

                //Response.Redirect("404.aspx?Massage=" + err.Message.ToString());

            }


            finally
            {
                clsCon.conn_new.Close();
                rdR_Status.Close();

            }   //finally
            return listrtn;
        }

        public string rerurndis_Name(string Id)
        {
            string disName = "";

            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);

                String Ssql = "SELECT Giv_Name from Tbl_Distributor where Dis_ID='"+Id+"'";
                //SqlDataReader ldr = Bestlife.ERP.DataAccess.clsCon.ReadTable(Ssql);


                rdR_Status = clsCon.ReadTable(Ssql);


                if (rdR_Status.Read())
                {
                    disName = rdR_Status["Giv_Name"].ToString();
                  
                }

            } //try

            catch (Exception err)
            {
                //Response.Redirect("404.aspx?Massage=" + err.Message.ToString());
            }
            finally
            {
                clsCon.conn_new.Close();
                rdR_Status.Close();
            }   //finally

            return disName;
        }

        public string rerurnDis_Plan(string Id)
        {
            string plan = "";

            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);

                String Ssql = "SELECT Dplan from Tbl_Distributor where Dis_ID='" + Id + "'";
                //SqlDataReader ldr = Bestlife.ERP.DataAccess.clsCon.ReadTable(Ssql);


                rdR_Status = clsCon.ReadTable(Ssql);


                if (rdR_Status.Read())
                {
                    plan = rdR_Status["Dplan"].ToString();

                }

            } //try

            catch (Exception err)
            {
                //Response.Redirect("404.aspx?Massage=" + err.Message.ToString());
            }
            finally
            {
                clsCon.conn_new.Close();
                rdR_Status.Close();
            }   //finally

            return plan;
        }
    }
}